package paidaxing.blog.user.service.impl;

import org.springframework.stereotype.Service;
import paidaxing.blog.core.service.UserInfoService;
import paidaxing.blog.user.dto.UserDTO;
import paidaxing.blog.user.service.UserService;

import jakarta.annotation.Resource;

/**
 * 用户信息服务实现类
 * 实现core模块定义的UserInfoService接口
 */
@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService {
    
    @Resource
    private UserService userService;

    @Override
    public UserInfoDTO getUserInfoById(Long userId) {
        UserDTO userDTO = userService.getUserInfo(userId);
        if (userDTO == null) {
            return null;
        }
        
        UserInfoDTO userInfoDTO = new UserInfoDTO();
        userInfoDTO.setId(userDTO.getId());
        userInfoDTO.setUsername(userDTO.getUsername());
        userInfoDTO.setNickname(userDTO.getNickname());
        userInfoDTO.setAvatar(userDTO.getAvatar());
        return userInfoDTO;
    }

    @Override
    public UserInfoDTO getPublicUserInfoById(Long userId) {
        UserDTO userDTO = userService.getUserInfo(userId);
        if (userDTO == null) {
            return null;
        }
        
        UserInfoDTO userInfoDTO = new UserInfoDTO();
        userInfoDTO.setId(userDTO.getId());
        userInfoDTO.setUsername(userDTO.getUsername());
        userInfoDTO.setNickname(userDTO.getNickname());
        userInfoDTO.setAvatar(userDTO.getAvatar());
        return userInfoDTO;
    }
}